package TCP;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package test
 * @date 2024/4/7 下午2:03
 */
public class Day09_Client {
    public static void main(String[] args) {
        try {
            InetAddress inetAddress = InetAddress.getLocalHost();
            Socket socket = new Socket(inetAddress, 8888);
            System.out.println("客户端启动成功");
            //获取输入输出流
            Scanner scanner = new Scanner(System.in);
            OutputStream outputStream = socket.getOutputStream();//输出流
            DataOutputStream dos = new DataOutputStream(outputStream);//数据输出流
            PrintWriter pw = new PrintWriter(dos, true);//打印输出流
            while (true) {
                System.out.println("请输入要发送的内容");
                String msg = scanner.nextLine();
                pw.println(msg);
                if ("bye".equals(msg)) {
                    break;
                }
            }
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
